import { ipcMain, BrowserWindow } from 'electron'

export const registerIPC = (win: BrowserWindow) => {
  ipcMain.on('window-minimize', () => win.minimize())
  ipcMain.on('window-maximize', () => {
    if (win.isMaximized()) {
      win.unmaximize()
    } else {
      win.maximize()
    }
  })
  ipcMain.on('window-close', () => win.close())

  // 新增：同步返回当前是否最大化
  ipcMain.handle('window-is-maximized-sync', () => win.isMaximized())

  // 新增：窗口最大化/还原时通知渲染进程
  win.on('maximize', () => {
    win.webContents.send('window-is-maximized')
  })
  win.on('unmaximize', () => {
    win.webContents.send('window-is-unmaximized')
  })
}